package lab02.test23;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test23 {

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");//xxxx-xx-xx
        SimpleDateFormat df = new SimpleDateFormat("EEEE");//星期几

        String str = df2.format(new Date()); //得到系统时间
        int nowyear = Integer.parseInt(str.substring(0, 4)); //得到系统年
        int nowmonth = Integer.parseInt(str.substring(5, 7)); //得到系统月
        int nowday = Integer.parseInt(str.substring(8, 10));//得到系统日
        long ssystem = System.currentTimeMillis();//得到系统的毫秒

        System.out.println("enter your birthday(like 19970101 information) :");
        Scanner sc = new Scanner(System.in);
        String birthday = sc.next();//得到字符串

        int ayear = Integer.parseInt(birthday.substring(0, 4));//得到年
        int amonth = Integer.parseInt(birthday.substring(4, 6));//得到年
        int aday = Integer.parseInt(birthday.substring(6, 8));//得到年

        String datenow = nowyear + "-" + amonth + "-" + aday;//计算在系统年字符串的生日
        java.util.Date nowdate = df2.parse(datenow);//转化字符串为日期
        long time = nowdate.getTime();//得到在系统年字符串的毫秒
        if (time >= ssystem) {//还未过生

            int day = Math.toIntExact((time - ssystem) / 1000 / 60 / 60 / 24 + 1);

            System.out.println(day);

            String newStr = df.format(nowdate);//将即将过生的日期字符串转化为星期几日期格式
            System.out.println(newStr);

        }
        else {

            //已过计算下一次生日

            String datenext = nowyear + 1 + "-" + amonth + "-" + aday;
            java.util.Date nextdate = df2.parse(datenext);
            long timenext = nextdate.getTime();
            int day = Math.toIntExact((timenext - ssystem) / 1000 / 60 / 60 / 24 + 1);

            System.out.println(day);

            String newStr = df.format(nextdate);
            System.out.println(newStr);
        }
    }
}
